#include "setalternativas.h"
#include "ui_setalternativas.h"

#include <iostream>
using namespace std;

setAlternativas::setAlternativas(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::setAlternativas)
{
    ui->setupUi(this);
    ui->lineEdit->setFocus();
}

setAlternativas::~setAlternativas()
{
    delete ui;
}

void setAlternativas::getAlternativas(AHP * ahp){
    for(list<string>::iterator it=alternativas.begin();it!=alternativas.end();it++){
        ahp->addAlternativa(*it);
    }
}

void setAlternativas::getCriterios(AHP * ahp){
    for(list<string>::iterator it = criterios.begin();it!=criterios.end();it++){
        ahp->addCriterio(*it);
    }
}

void setAlternativas::on_pushButton_clicked()
{
    if(ui->lineEdit->text()!=""){
        bool add=true;
        if (ui->comboBox->currentIndex()==1){
            for(list<string>::iterator it=this->criterios.begin();it!=this->criterios.end();it++){
                if(*it==ui->lineEdit->text().toStdString()){
                    add=false;
                }
            }
            if(add){
                ui->listWidget_2->addItem(ui->lineEdit->text());
                this->criterios.push_back(ui->lineEdit->text().toStdString());
            }
        }
        else{
            for(list<string>::iterator it=this->alternativas.begin();it!=this->alternativas.end();it++){
                if(*it==ui->lineEdit->text().toStdString()){
                    add=false;
                }
            }
            if(add){
                ui->listWidget->addItem(ui->lineEdit->text());
                this->alternativas.push_back(ui->lineEdit->text().toStdString());
            }
        }
        ui->lineEdit->setFocus();
        ui->lineEdit->clear();
    }
}

void setAlternativas::on_pushButton_2_clicked()
{
    this->accept();
}


void setAlternativas::on_pushButton_3_clicked()
{
    this->alternativas.clear();
    this->criterios.clear();
    this->reject();
}

void setAlternativas::on_buttonBox_rejected()
{

}
